
#include "Sphere.h"
#include "BBox.h"


Sphere::Sphere(const Vec3 &centre, float radius, float value)
:	SpatialData(),
 	centre(centre),
 	radius(radius),
 	centreValue(value)
{
	bbox = BBox(centre - radius, centre + radius);
}

void Sphere::getValueRange(float *min, float *max)
{
	*min = 0.0;
	*max = centreValue;
}

float Sphere::getValue(float x, float y, float z){
	const Vec3 point = Vec3(x, y, z);
	float dist = (point - centre).length();

	if(dist <= radius)
		return centreValue*(1.0 - (dist/radius));
	else
		return 0.0;
}
